export default ({ app: { router }, store }) => {
  router.afterEach((to, from) => {
    try {
      // 百度统计
      document.getElementById('g_baidu') && document.getElementById('g_baidu').remove();
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8e45646333c0b122d556ae44e337c90e";
      hm.id = "g_baidu"
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
      window._hmt = window._hmt || []
      window._hmt.push(['_trackPageview', to.fullPath])

      // 百度自动链接提交
      linkSubmit()
    } catch (e) {}
  })
}

function linkSubmit() {
  document.getElementById('link_baidu') && document.getElementById('link_baidu').remove();
  var bp = document.createElement('script');
  bp.id = 'link_baidu'
  var curProtocol = window.location.protocol.split(':')[0];
  if (curProtocol === 'https'){
    bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
    bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);
}
